Port all of babl to use use babl_set_destructor
authorØyvind Kolås <pippin@gimp.org>
Sun, 27 Jun 2010 13:50:41 +0000 (14:50 +0100)
committerØyvind Kolås <pippin@gimp.org>
Sun, 27 Jun 2010 16:30:55 +0000 (17:30 +0100)
Making all babl objects be free-able with babl_free means that overall
management code can be directly shared between the different
babl-classes.

28 files changed:
babl/Makefile.am
babl/babl-class.h
babl/babl-classes.h
babl/babl-component.c
babl/babl-component.h
babl/babl-conversion.c
babl/babl-conversion.h
babl/babl-db.c
babl/babl-db.h
babl/babl-extension.c
babl/babl-extension.h
babl/babl-fish-path.c
babl/babl-fish.c
babl/babl-format.c
babl/babl-format.h
babl/babl-hash-table.c
babl/babl-hash-table.h
babl/babl-image.c
babl/babl-internal.h
babl/babl-list.c
babl/babl-list.h
babl/babl-model.c
babl/babl-model.h
babl/babl-sampling.c
babl/babl-sampling.h
babl/babl-type.c
babl/babl-type.h
babl/babl.c

index d62125cfff7e9f2202f02e382cf2328525c80300..12cd9694336d147ea65af342d1029b1ce546d409 100644 (file)
@@ -11,7 +11,6 @@ c_sources =                           \
        babl-component.c                \
        babl-conversion.c               \
        babl-core.c                     \
-       babl-cpuaccel.c                 \
        babl-db.c                       \
        babl-extension.c                \
        babl-fish-path.c                \
@@ -32,6 +31,7 @@ c_sources =                           \
        babl-sanity.c                   \
        babl-type.c                     \
        babl-util.c                     \
+       babl-cpuaccel.c                 \
        babl-version.c
 
 h_sources  =                           \
index 534c476d0cf011e8aeb5a19c2b82bfb60b5aec91..4e9bbafc4ecb524a934cb2c43941fa716f918998 100644 (file)
@@ -33,25 +33,12 @@ typedef int  (*BablEachFunction) (Babl *entry,
  * to be iterated over, common functionality is defined through these
  * macros.
  */
-#define BABL_CLASS_DECLARE(klass)                                  \
-                                                                   \
-Babl * babl_##klass##_from_id        (int id);                     \
-void   babl_##klass##_class_init     (void);                       \
-void   babl_##klass##_class_destroy  (void);                       \
-void   babl_##klass##_class_for_each (BablEachFunction  each_fun,  \
-                                      void             *user_data)
-
-/* If a class is declared as a "named class" it means it is a class
- * that has a specific name connected to it, that also allows defining
- * a new instance. These classes share common functionality with the
- * non_name classes but have two extra methods, the means to lookup by
- * name, as well as to create new named objects that later can be
- * looked up. These methods are babl_klass() babl_klass_new() but they
- * are declared outside of this macro.
- */
-#define BABL_NAMED_CLASS_DECLARE(klass) \
-BABL_CLASS_DECLARE (klass)
-
+#define BABL_CLASS_DECLARE(klass)                                    \
+                                                                     \
+BablDb * babl_##klass##_db (void);                                   \
+Babl   * babl_##klass##_from_id        (int id);                     \
+void     babl_##klass##_class_for_each (BablEachFunction  each_fun,  \
+                                        void             *user_data)
 
 /* common header for any item inserted into database, the actual
  * implementation of babl-instance is in babl-internal
index eeaa262be44633232dc19c6817ac5617d4b3a0c3..0427c3059cdd4fd242fc3336ad61d0ef955294d0 100644 (file)
@@ -20,6 +20,7 @@
 #define _BABL_CLASSES_H
 
 #include "babl-class.h"
+#include "babl-db.h"
 
 /* magic number used at the start of all babl objects, used to do
  * differentiation in polymorphic functions. (as well as manual type
@@ -54,7 +55,6 @@ enum {
   BABL_SKY
 };
 
-
 #include "babl-type.h"
 #include "babl-sampling.h"
 #include "babl-component.h"
index 301e64df3e7fc61a350724f43797b3b5f6312940..54a06b3fe83b8133f6b238738eb93d25562c7126 100644 (file)
 
 #include <stdarg.h>
 
-
-static int
-each_babl_component_destroy (Babl *babl,
-                             void *data)
-{
-  babl_free (babl);
-  return 0;  /* continue iterating */
-}
-
 static Babl *
 component_new (const char *name,
                int         id,
index df9d7199342deda699a012a0348badacdf344b6c..2c45cdcb58e469716f9581d6ab498c74983341bd 100644 (file)
@@ -22,7 +22,7 @@
 
 /****************************************************************/
 /* BablComponent */
-BABL_NAMED_CLASS_DECLARE (component);
+BABL_CLASS_DECLARE (component);
 
 
 typedef struct
index 422e2dda21bf17db326a8203ac3c17c1c87c816b..ea6be81c56d8808ce97f6dbbb38f07a036136520 100644 (file)
 #include "babl-internal.h"
 #include "babl-db.h"
 
-static int
-each_babl_conversion_destroy (Babl *babl,
-                              void *data)
-{
-  babl_free (babl);
-  return 0;  /* continue iterating */
-}
-
 static Babl *
 conversion_new (const char    *name,
                 int            id,
index d231b6484b060bd4cf3dc3786c58d63709148e4d..fbbb2798ced9e5fbbb8965ade30c25031bfe40ce 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef _BABL_CONVERSION_H
 #define _BABL_CONVERSION_H
 
-BABL_NAMED_CLASS_DECLARE (conversion);
+BABL_CLASS_DECLARE (conversion);
 
 Babl * babl_conversion (const char *name);
 
index 7825cc0a0fe50f863df7be36232d1a1439903ac4..fed9a05e07df7cbdb283dc793ea7714aee753174 100644 (file)
@@ -55,10 +55,33 @@ db_hash_by_id (BablHashTable *htab, Babl *item)
   return babl_hash_by_int (htab, item->instance.id);
 }
 
+static int
+each_free (Babl *data,
+           void *foo)
+{
+  babl_free (data);
+  return 0;
+}
+
+static int
+babl_db_destroy (void *data)
+{
+  BablDb *db = data;
+  babl_assert (db);
+
+  babl_db_each (db, each_free, NULL);
+  babl_mutex_destroy (db->mutex);
+  babl_free (db->name_hash);
+  babl_free (db->id_hash);
+  babl_free (db->babl_list);
+  return 0;
+}
+
 BablDb *
 babl_db_init (void)
 {
   BablDb *db = babl_calloc (sizeof (BablDb), 1);
+  babl_set_destructor (db, babl_db_destroy);
 
   db->name_hash = babl_hash_table_init (db_hash_by_name, db_find_by_name);
   db->id_hash = babl_hash_table_init (db_hash_by_id, db_find_by_id);
@@ -68,17 +91,6 @@ babl_db_init (void)
   return db;
 }
 
-void
-babl_db_destroy (BablDb *db)
-{
-  babl_assert (db);
-
-  babl_mutex_destroy (db->mutex);
-  babl_hash_table_destroy (db->name_hash);
-  babl_hash_table_destroy (db->id_hash);
-  babl_list_destroy (db->babl_list);
-  babl_free (db);
-}
 
 Babl *
 babl_db_find (BablDb     *db,
index 6b4e6ff893ba7509e2a60a654c2e423bf9e85a3f..a07a17bafcfade35fa066612669012851100612d 100644 (file)
@@ -42,9 +42,6 @@ typedef struct _BablDb
 BablDb *
 babl_db_init (void);
 
-void
-babl_db_destroy (BablDb *db);
-
 void
 babl_db_each (BablDb           *db,
               BablEachFunction  each_fun,
index 1628d038a803ce69ac8262f0d1914705c6b253e0..19735888f86d3fee3cea765b47439f1f8b79275b 100644 (file)
 
 #include "config.h"
 
-#define BABL_PATH              LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
-
-#define BABL_INIT_HOOK         init_hook ();
-#define BABL_DESTROY_HOOK      destroy_hook ();
 
 #ifdef BABL_DYNAMIC_EXTENSIONS
 /* must be defined before inclusion of babl-internal.h */
@@ -37,8 +33,6 @@
 #include <string.h>
 #include <stdarg.h>
 
-static int   each_babl_extension_destroy (Babl *babl, void *data);
-
 static Babl *babl_extension_current_extender = NULL;
 
 Babl *
@@ -55,6 +49,9 @@ babl_set_extender (Babl *new_extender)
   babl_extension_current_extender = new_extender;
 }
 
+static int
+babl_extension_destroy (void *data);
+
 static Babl *
 extension_new (const char *path,
                void       *dl_handle,
@@ -63,6 +60,7 @@ extension_new (const char *path,
   Babl *babl;
 
   babl                = babl_malloc (sizeof (BablExtension) + strlen (path) + 1);
+  babl_set_destructor (babl, babl_extension_destroy);
   babl->instance.name = (char *) babl + sizeof (BablExtension);
   strcpy (babl->instance.name, path);
   babl->instance.id         = 0;
@@ -93,7 +91,11 @@ babl_extension_base (void)
   void  (*destroy)(void) = NULL;
 
   if (!db)
-    db = babl_db_init ();
+    {
+      babl_extension_quiet_log ();
+      babl_set_extender (NULL);
+      db = babl_db_init ();
+    }
   babl = extension_new ("BablBase",
                         dl_handle,
                         destroy);
@@ -111,15 +113,7 @@ babl_extension_base (void)
   return babl;
 }
 
-static void
-init_hook (void)
-{
-  babl_extension_quiet_log ();
-  babl_set_extender (NULL);
-}
-
-static void
-destroy_hook (void)
+void babl_extension_deinit (void)
 {
   babl_free (babl_quiet);
   babl_quiet = NULL;
@@ -187,7 +181,7 @@ load_failed (Babl *babl)
 {
   if (babl)
     {
-      each_babl_extension_destroy (babl, NULL);
+      babl_free (babl);
     }
   babl_set_extender (NULL);
   return NULL;
@@ -278,17 +272,6 @@ babl_extension_load_dir (const char *base_path)
     }
 }
 
-static const char *
-babl_dir_list (void)
-{
-  const char *ret;
-
-  ret = getenv ("BABL_PATH");
-  if (!ret)
-    ret = BABL_PATH;
-  return ret;
-}
-
 static char *
 expand_path (char *path)
 {
@@ -325,7 +308,7 @@ expand_path (char *path)
 
 /*  parse the provided colon seperated list of paths to search
  */
-static void
+void
 babl_extension_load_dir_list (const char *dir_list)
 {
   int         eos = 0;
@@ -364,25 +347,18 @@ babl_extension_load_dir_list (const char *dir_list)
   babl_free (path);
 }
 
-static void
-dynamic_init_hook (void)
-{
-  babl_extension_load_dir_list (babl_dir_list ());
-}
-
 #endif
 
+
 static int
-each_babl_extension_destroy (Babl *babl,
-                             void *data)
+babl_extension_destroy (void *data)
 {
+  Babl *babl = data;
   if (babl->extension.destroy)
     babl->extension.destroy ();
   if (babl->extension.dl_handle)
     dlclose (babl->extension.dl_handle);
-
-  babl_free (babl);
-  return 0;  /* continue iterating */
+  return 0;
 }
 
 BABL_CLASS_IMPLEMENT (extension)
index cd7f83134c1d6c4509c6129c834ef66f5da3bab9..4c2610a5415c75df2337a1d203465453b83b89cd 100644 (file)
 
 /****************************************************************/
 /* BablExtension */
-BABL_NAMED_CLASS_DECLARE (extension);
+BABL_CLASS_DECLARE (extension);
 /*
  * BablExtension objects are only used internally in babl.
  */
 
 Babl * babl_extension (const char *name);
-
+void   babl_extension_load_dir_list (const char *dir_list);
 
 typedef struct
 {
index 2622cb33d8a74254c00d3c934e722b87163a8491..da5e0b0eac78471ae2c6fcbc18b13e8ced3a4700 100644 (file)
@@ -236,6 +236,16 @@ create_name (char       *buf,
   return buf;
 }
 
+static int
+babl_fish_path_destroy (void *data)
+{
+  Babl *babl=data;
+  if (babl->fish_path.conversion_list)
+    babl_free (babl->fish_path.conversion_list);
+  babl->fish_path.conversion_list = NULL;
+  return 0;
+}
+
 Babl *
 babl_fish_path (const Babl *source,
                 const Babl *destination)
@@ -255,6 +265,7 @@ babl_fish_path (const Babl *source,
 
   babl = babl_calloc (1, sizeof (BablFishPath) +
                       strlen (name) + 1);
+  babl_set_destructor (babl, babl_fish_path_destroy);
 
   babl->class_type                = BABL_FISH_PATH;
   babl->instance.id               = babl_fish_get_id (source, destination);
@@ -284,12 +295,11 @@ babl_fish_path (const Babl *source,
 
     get_conversion_path (&pc, (Babl *) source, 0, max_path_length ());
     babl_mutex_unlock (babl_format_mutex);
-    babl_list_destroy (pc.current_path);
+    babl_free (pc.current_path);
   }
 
   if (babl_list_size (babl->fish_path.conversion_list) == 0)
     {
-      babl_list_destroy (babl->fish_path.conversion_list);
       babl_free (babl);
       return NULL;
     }
index a09efaf2975fec195fefea14c8ea73454d2db938..dad518b2e474abc1ed502c0dd89eac3ab83bbdba 100644 (file)
@@ -22,7 +22,6 @@
 #include <string.h>
 #include <stdarg.h>
 
-
 typedef struct _BablFindFish BablFindFish;
 
 typedef struct _BablFindFish
@@ -48,14 +47,6 @@ static int
 find_memcpy_fish (Babl *item,
                   void *data);
 
-static int
-each_babl_fish_destroy (Babl *babl,
-                        void *data);
-
-
-/* ====================================== */
-
-
 static int
 find_fish_path (Babl *item,
                 void *data)
@@ -145,14 +136,6 @@ babl_fish_get_id (const Babl *source,
   return id;
 }
 
-BablDb *
-babl_fish_db (void)
-{
-  if (!db)
-    db = babl_db_init ();
-  return db;
-}
-
 Babl *
 babl_fish (const void *source,
            const void *destination)
@@ -278,16 +261,4 @@ babl_fish (const void *source,
   }
 }
 
-
-
-static int
-each_babl_fish_destroy (Babl *babl,
-                        void *data)
-{
-  if (babl->class_type == BABL_FISH_PATH)
-    babl_list_destroy (babl->fish_path.conversion_list);
-  babl_free (babl);
-  return 0;  /* continue iterating */
-}
-
 BABL_CLASS_MINIMAL_IMPLEMENT (fish);
index 227dab066634c4128d237ecbf97b45665b804e66..4c75d3cf684b58162b0fcedae50f8de476bacce5 100644 (file)
@@ -34,20 +34,11 @@ static int babl_format_destruct (void *babl)
       babl_free (format->image_template);
       format->image_template = NULL;
     }
+  if (format->from_list)
+    babl_free (format->from_list);
   return 0;
 }
 
-static int
-each_babl_format_destroy (Babl *babl,
-                          void *data)
-{
-  if (babl->format.from_list)
-    babl_list_destroy (babl->format.from_list);
-  babl_free (babl);
-
-  return 0;  /* continue iterating */
-}
-
 static Babl *
 format_new (const char     *name,
             int             id,
index f130bcdd8a514074cc1e724784b9064a84eecd25..fb8dfac1087890ff3dff398b027baf5af4068ccd 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef _BABL_FORMAT_H
 #define _BABL_FORMAT_H
 
-BABL_NAMED_CLASS_DECLARE (format);
+BABL_CLASS_DECLARE (format);
 
 typedef struct
 {
index 8afc3aa4316718e8b9f9cc2d26e41ef22519adb5..99b74277c38e684d80b860c8ada7c91bc981df57 100644 (file)
@@ -143,6 +143,17 @@ babl_hash_table_size (BablHashTable *htab)
     return htab->mask + 1;
 }
 
+
+static int
+babl_hash_table_destroy (void *data)
+{
+  BablHashTable *htab = data;
+  babl_free (htab->data_table);
+  babl_free (htab->chain_table);
+  return 0;
+}
+
+
 BablHashTable *
 babl_hash_table_init (BablHashValFunction  hfunc,
                       BablHashFindFunction ffunc)
@@ -153,7 +164,7 @@ babl_hash_table_init (BablHashValFunction  hfunc,
   babl_assert(ffunc);
 
   htab = babl_calloc (sizeof (BablHashTable), 1);
-  babl_assert (htab);
+  babl_set_destructor (htab, babl_hash_table_destroy);
 
   htab->data_table = NULL;
   htab->chain_table = NULL;
@@ -171,16 +182,6 @@ babl_hash_table_init (BablHashValFunction  hfunc,
   return htab;
 }
 
-void
-babl_hash_table_destroy (BablHashTable *htab)
-{
-  babl_assert (htab);
-
-  babl_free (htab->data_table);
-  babl_free (htab->chain_table);
-  babl_free (htab);
-}
-
 int
 babl_hash_table_insert (BablHashTable *htab,
                         Babl          *item)
index ec546f36cad4a2bd49ec13541a5ddc16ca44fdca..f56d02fb6706bdfa68c36a600a8afc9460b9e33a 100644 (file)
@@ -65,8 +65,4 @@ babl_hash_table_find (BablHashTable       *htab,
                       BablHashFindFunction find_func,
                       void                *data);
 
-void
-babl_hash_table_destroy (BablHashTable *htab);
-
-
 #endif
index ed28c899f7fc99b19312858fc106f67585c2c178..631fe6dab497578355f6228646abeb73560b87db 100644 (file)
@@ -237,15 +237,3 @@ babl_image_new (void *first,
   babl = image_new (format, model, components, component, sampling, type, data, pitch, stride);
   return babl;
 }
-
-void
-babl_image_class_destroy (void)
-{
-  /* nothing to do */
-}
-
-void
-babl_image_class_init (void)
-{
-  /* nothing to do */
-}
index 70538e92d2b1bd5e8ae4c831f0eb13596371203a..1f5fe23e4ee9dc28c3aadc5954feaf4c3f557e7c 100644 (file)
@@ -40,9 +40,9 @@
 #include "babl.h"
 #define _BABL_INTERNAL_H
 
-#include "babl-class.h"
 #include "babl-classes.h"
 #include "babl-introspect.h"
+#include "babl-class.h"
 #include "babl-list.h"
 #include "babl-hash-table.h"
 #include "babl-db.h"
@@ -80,13 +80,13 @@ Babl   * babl_extender                  (void);
 void     babl_set_extender              (Babl           *new_extender);
 
 Babl   * babl_extension_quiet_log       (void);
+void     babl_extension_deinit          (void);
 
 long     babl_fish_reference_process    (Babl           *babl,
                                          BablImage      *source,
                                          BablImage      *destination,
                                          long            n);
 
-BablDb * babl_fish_db                   (void);
 Babl   * babl_fish_reference            (const Babl     *source,
                                          const Babl     *destination);
 Babl   * babl_fish_simple               (BablConversion *conversion);
@@ -243,19 +243,6 @@ void         babl_internal_init    (void);
 void         babl_internal_destroy (void);
 
 
-#ifndef BABL_INIT_HOOK
-#define BABL_INIT_HOOK
-#endif
-#ifndef BABL_PRE_INIT_HOOK
-#define BABL_PRE_INIT_HOOK
-#endif
-#ifndef BABL_DESTROY_HOOK
-#define BABL_DESTROY_HOOK
-#endif
-#ifndef BABL_DESTROY_PRE_HOOK
-#define BABL_DESTROY_PRE_HOOK
-#endif
-
 /* this template is expanded in the files including babl-internal.h,
  * generating code, the declarations for these functions are found in
  * the BABL_CLASS expansions done in babl.h as well, thus babl.h needs
@@ -263,22 +250,13 @@ void         babl_internal_destroy (void);
  */
 
 #define BABL_CLASS_MINIMAL_IMPLEMENT(klass)                   \
-void                                                          \
-babl_##klass##_class_init (void)                              \
+                                                              \
+BablDb *                                                      \
+babl_##klass##_db (void)                                      \
 {                                                             \
-  BABL_PRE_INIT_HOOK;                                         \
   if (!db)                                                    \
     db=babl_db_init ();                                       \
-  BABL_INIT_HOOK;                                             \
-}                                                             \
-                                                              \
-void                                                          \
-babl_##klass##_class_destroy (void)                           \
-{                                                             \
-  BABL_DESTROY_PRE_HOOK;                                      \
-  babl_db_each (db,each_babl_##klass##_destroy, NULL);        \
-  babl_db_destroy (db);                                       \
-  BABL_DESTROY_HOOK;                                          \
+  return db;                                                  \
 }                                                             \
                                                               \
 void                                                          \
@@ -319,7 +297,7 @@ babl_##klass##_from_id (int id)                               \
       babl_fatal ("%s(%i): not found", G_STRFUNC, id);        \
     }                                                         \
   return babl;                                                \
-}
+} \
 
 #define BABL(obj)  ((Babl*)(obj))
 
index 2cf1251fe547f07d4b24943bb418135b5204a364..49647bb7d6a137c2a2e7df2da3f94d787dcbbec4 100644 (file)
@@ -31,12 +31,20 @@ babl_list_init (void)
   return babl_list_init_with_size (BABL_LIST_INITIAL_SIZE);
 }
 
+static int
+babl_list_destroy (void *data)
+{
+  BablList *list = data;
+  babl_free (list->items);
+  return 0;
+}
+
 BablList *
 babl_list_init_with_size (int initial_size)
 {
   BablList *list = babl_calloc (sizeof (BablList), 1);
 
-  babl_assert (list);
+  babl_set_destructor (list, babl_list_destroy);
 
   if (initial_size == 0)
     initial_size = 1;
@@ -51,15 +59,6 @@ babl_list_init_with_size (int initial_size)
   return list;
 }
 
-void
-babl_list_destroy (BablList *list)
-{
-    babl_assert (list);
-
-    babl_free (list->items);
-    babl_free (list);
-}
-
 void
 babl_list_insert_last (BablList *list,
                        Babl     *item)
index c9c64e8f8e6429bd33416aad7b6c5acffa6aba09..60cdf6eb2eb82da419c60cc8639127b4f938237e 100644 (file)
@@ -36,9 +36,6 @@ babl_list_init (void);
 BablList *
 babl_list_init_with_size (int initial_size);
 
-void
-babl_list_destroy (BablList *list);
-
 int
 babl_list_size (BablList *list);
 
index 2b26e91e3be3da88f830bc051cd8f1fb19c8f555..eb7eee429ccb975c354a3e8c0c7d9dbeaab64971 100644 (file)
 #include "babl-internal.h"
 #include "babl-db.h"
 
-
 static int
-each_babl_model_destroy (Babl *babl,
-                         void *data)
+babl_model_destroy (void *data)
 {
+  Babl *babl = data;
   if (babl->model.from_list)
-    babl_list_destroy (babl->model.from_list);
-  babl_free (babl);
-  return 0;  /* continue iterating */
+    babl_free (babl->model.from_list);
+  return 0; 
 }
 
 static char *
@@ -60,6 +58,7 @@ model_new (const char     *name,
   babl = babl_malloc (sizeof (BablModel) +
                       sizeof (BablComponent *) * (components) +
                       strlen (name) + 1);
+  babl_set_destructor (babl, babl_model_destroy);
   babl->model.component = (void *) (((char *) babl) + sizeof (BablModel));
   babl->instance.name   = (void *) (((char *) babl->model.component) + sizeof (BablComponent *) * (components));
 
index 617c91c8fb57cdda4ee446be6be64eb58d7ef95f..0a4786be530295812983fcd20ab1d65fec6459c3 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef _BABL_MODEL_H
 #define _BABL_MODEL_H
 
-BABL_NAMED_CLASS_DECLARE (model);
+BABL_CLASS_DECLARE (model);
 
 typedef struct
 {
index d3fa63721285f0ac60944c3d3a5f6fd48a60acae..a3fa3a6db34344e68a0666fa8da1630af0f7d45a 100644 (file)
@@ -47,9 +47,7 @@ static int
 each_babl_sampling_destroy (Babl *babl,
                             void *data)
 {
-  if (babl->sampling.from_list)
-    babl_list_destroy (babl->sampling.from_list);
-  return 0;  /* continue iterating */
+  return 0; 
 }
 
 void
index 869e3de86d08a5dbd0e4a9a4a6bfaeefbd3f2d45..82e6d15946e213a7245d8a989fae812e62ac3002 100644 (file)
@@ -24,10 +24,12 @@ BABL_CLASS_DECLARE (sampling);
 typedef struct
 {
   BablInstance     instance;
-  BablList         *from_list;
   int              horizontal;
   int              vertical;
   char             name[4];
 } BablSampling;
 
+void
+babl_sampling_class_init (void);
+
 #endif
index c150e2ca52a302698e0db5cadfa287903846af55..467b33ff17df4c17a12fd04e56a9b0f8357769ab 100644 (file)
 #include "babl-internal.h"
 #include "babl-db.h"
 
-
 static int
-each_babl_type_destroy (Babl *babl,
-                        void *data)
+babl_type_destroy (void *data)
 {
+  Babl *babl = data;
   if (babl->type.from_list)
-    babl_list_destroy (babl->type.from_list);
-  babl_free (babl);
-  return 0;  /* continue iterating */
+    babl_free (babl->type.from_list);
+  return 0; 
 }
 
-
 static Babl *
 type_new (const char *name,
           int         id,
@@ -47,6 +44,7 @@ type_new (const char *name,
   babl_assert (bits % 8 == 0);
 
   babl                 = babl_malloc (sizeof (BablType) + strlen (name) + 1);
+  babl_set_destructor (babl, babl_type_destroy);
   babl->instance.name  = (void *) ((char *) babl + sizeof (BablType));
   babl->class_type     = BABL_TYPE;
   babl->instance.id    = id;
index 10e40409aefabe27d207e799de74381c572d1b09..8030fe57317344b5785938ee69f41597d97cbebc 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef _BABL_TYPE_H
 #define _BABL_TYPE_H
 
-BABL_NAMED_CLASS_DECLARE (type);
+BABL_CLASS_DECLARE (type);
 
 typedef struct
 {
index 6386f6005684012d6b35bcc781e3455a389c0d1e..bc3f7de8f7ea86144d5de33482f77e61078e2b8e 100644 (file)
 
 static int ref_count = 0;
 
+#define BABL_PATH              LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
+
+static const char *
+babl_dir_list (void)
+{
+  const char *ret;
+
+  ret = getenv ("BABL_PATH");
+  if (!ret)
+    ret = BABL_PATH;
+  return ret;
+}
+
 void
 babl_init (void)
 {
@@ -29,20 +42,20 @@ babl_init (void)
   if (ref_count++ == 0)
     {
       babl_internal_init ();
-      babl_type_class_init ();
       babl_sampling_class_init ();
-      babl_component_class_init ();
-      babl_model_class_init ();
-      babl_format_class_init ();
-      babl_conversion_class_init ();
+      babl_type_db ();
+      babl_component_db ();
+      babl_model_db ();
+      babl_format_db ();
+      babl_conversion_db ();
+      babl_extension_db ();
+      babl_fish_db ();
       babl_core_init ();
       babl_sanity ();
       babl_extension_base ();
       babl_sanity ();
-      babl_extension_class_init ();
-      babl_sanity ();
-      babl_fish_class_init ();
-      babl_sanity ();
+
+      babl_extension_load_dir_list (babl_dir_list ());
     }
 }
 
@@ -63,14 +76,15 @@ babl_exit (void)
             }
         }
 
-      babl_extension_class_destroy ();
-      babl_fish_class_destroy ();
-      babl_conversion_class_destroy ();
-      babl_format_class_destroy ();
-      babl_model_class_destroy ();
-      babl_component_class_destroy ();
-      babl_sampling_class_destroy ();
-      babl_type_class_destroy ();
+      babl_extension_deinit ();
+      babl_free (babl_extension_db ());;
+      babl_free (babl_fish_db ());;
+      babl_free (babl_conversion_db ());;
+      babl_free (babl_format_db ());;
+      babl_free (babl_model_db ());;
+      babl_free (babl_component_db ());;
+      babl_free (babl_type_db ());;
+
       babl_internal_destroy ();
 #if BABL_DEBUG_MEM
       babl_memory_sanity ();